package com.jiangkang.example.web;

import com.jiangkang.example.mapper.CustomMapper;
import com.jiangkang.example.mapper.MenuMapper;
import com.jiangkang.example.service.IRoleService;
import com.jiangkang.example.service.IUserService;
import com.jiangkang.example.api.ZikaoshuExamlpeTwoServiceApi;
import com.jiangkang.example.dto.GlobalResponse;
import com.jiangkang.example.po.Menu;
import com.jiangkang.example.po.Role;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author fang
 * @describe 用户相关控制层
 * @date 2019-03-11
 */
@RestController
@RequestMapping(value = "/test")
@Slf4j
public class UserController {

	@Autowired
	private IUserService userService;
	@Autowired
	private ZikaoshuExamlpeTwoServiceApi zikaoshuExamlpeTwoServiceApi;



	@Autowired
	private IRoleService roleService;
	@Autowired
	private MenuMapper menuMapper;

	@Autowired
	private CustomMapper customMapper;

	@GetMapping("/getAllRole")
	private List<Role> getAllRole(){
		List <Role> list = roleService.list();
		return list;
	}
	@GetMapping("/getMenuByRoleId")
	private List<Menu> getMenuByRoleId(){
	List <Menu> ms = menuMapper.getMenuByRoleId("2");
	return ms;
	}

	@GetMapping("/getMenuByRole")
	private List<Menu> getMenuByRole(){
		Role role = new Role();
		role.setId(1);
		List <Menu> ms = menuMapper.getMenuByRole(role);
		return ms;
	}

    @GetMapping("/getMenuByRoleIdCustom")
	private List<Menu> getMenuByRoleIdCustom(){
	List <Menu> ms = customMapper.getMenuByRoleId("2");
	return ms;
	}

	@GetMapping("/getMenuByRoleCustom")
	private List<Menu> getMenuByRoleCustom(){
		Role role = new Role();
		role.setId(1);
		List <Menu> ms = customMapper.getMenuByRole(role);
		return ms;
	}


/*
	//http://localhost:20001/userbg-one/queryUserByStudentId?studentId=19SL8T6
	@GetMapping(value = "/queryUserByStudentId", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public UserPartialInfo queryUserByStudentId(@RequestParam("studentId") String studentId) {
		return userService.queryUserByStudentId(studentId);
	}
	//http://localhost:20001/userbg-one/byFeign?studentId=1973MXO
	@GetMapping(value = "/byFeign", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public UserPartialInfo byFeign(@RequestParam("studentId") String studentId) {
		return zikaoshuExamlpeTwoServiceApi.queryUserByStudentId(studentId);
	}
	*/
    //http://localhost:20001/userbg-one/queryUserByStudentIdRes?studentId=19SL8T6
	@GetMapping(value = "/queryUserByStudentIdRes", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public GlobalResponse queryUserByStudentId(@RequestParam("studentId") String studentId) {
		GlobalResponse res  = new GlobalResponse();
		res.setStatus("1");
		res.setResult(userService.queryUserByStudentId(studentId));
		return res;
	}
	//http://localhost:20001/userbg-one/byFeignRes?studentId=1973MXO
	@GetMapping(value = "/byFeignRes", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public GlobalResponse byFeignRes(@RequestParam("studentId") String studentId) {
		return zikaoshuExamlpeTwoServiceApi.queryUserByStudentId(studentId);
	}



}
